package com.suypower.carManage.action;

import javax.servlet.ServletException;

import com.jarp.db.DAO;
import com.opensymphony.xwork2.ActionSupport;
import com.suypower.carManage.comm.ConstUtil;

public class RepairAction extends ActionSupport {

	private String id;
	private String car_code;
	private String driver;
	private String repair_date;
	private String area;
	private String repair_price;
	private String mileage;
	private String type;
	private String approve_date;
	private String approve_person;
	private String clean;
	private String repair_content;
	private String remark;

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getCar_code() {
		return car_code;
	}

	public void setCar_code(String carCode) {
		car_code = carCode;
	}

	public String getDriver() {
		return driver;
	}

	public void setDriver(String driver) {
		this.driver = driver;
	}

	public String getRepair_date() {
		return repair_date;
	}

	public void setRepair_date(String repairDate) {
		repair_date = repairDate;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

	public String getRepair_price() {
		return repair_price;
	}

	public void setRepair_price(String repairPrice) {
		repair_price = repairPrice;
	}

	public String getMileage() {
		return mileage;
	}

	public void setMileage(String mileage) {
		this.mileage = mileage;
	}

	public String getApprove_date() {
		return approve_date;
	}

	public void setApprove_date(String approveDate) {
		approve_date = approveDate;
	}

	public String getApprove_person() {
		return approve_person;
	}

	public void setApprove_person(String approvePerson) {
		approve_person = approvePerson;
	}

	public String getClean() {
		return clean;
	}

	public void setClean(String clean) {
		this.clean = clean;
	}

	public String getRepair_content() {
		return repair_content;
	}

	public void setRepair_content(String repairContent) {
		repair_content = repairContent;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String execute() {
		String res = "";
		DAO dao = new DAO();
		String sql = "";
		if (id != null && !id.equals("")) {
			sql = "UPDATE tb_repair SET car_code = '" + car_code
					+ "', driver = '" + driver + "', repair_date = '"
					+ repair_date + "', area = '" + area
					+ "', repair_price = '" + repair_price + "', mileage = '"
					+ mileage + "', approve_date = '" + approve_date
					+ "', approve_person = '" + approve_person + "', clean = '"
					+ clean + "', repair_content = '" + repair_content
					+ "', remark = '" + remark + "', type = '" + type
					+ "' where id=" + id;
		} else {
			sql = "INSERT INTO tb_repair(car_code,driver,repair_date,area,repair_price,mileage,approve_date,approve_person,clean,repair_content,remark,type)VALUES('"
					+ car_code
					+ "','"
					+ driver
					+ "','"
					+ repair_date
					+ "','"
					+ area
					+ "','"
					+ repair_price
					+ "','"
					+ mileage
					+ "','"
					+ approve_date
					+ "','"
					+ approve_person
					+ "','"
					+ clean
					+ "','"
					+ repair_content
					+ "','"
					+ remark
					+ "','"
					+ type
					+ "')";
		}

		int count = 0;
		try {
			count = dao.execCommand(ConstUtil.DBNAME, sql);
			if (count > 0) {
				res = this.SUCCESS;
			} else {
				res = this.ERROR;
			}
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return res;
	}
}
